package com.zb.controller;
import com.zb.dto.Result;
import com.zb.entity.Exchangescore;
import com.zb.util.PageUtil;
import com.zb.service.ExchangescoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Map;


@RestController
@RequestMapping("/exchangescore")
public class ExchangescoreController {

    @Autowired
    private ExchangescoreService exchangescoreService;


    @PostMapping("/insertExchange")
    public Result insertExchangeScore(Exchangescore exchangescore) throws Exception{
        return Result.succ("新增成功！",exchangescoreService.qdtxAddExchangescore(exchangescore));
    }



    @RequestMapping("/search")
    @ResponseBody
    public PageUtil<Exchangescore> searchExchangescore(@RequestParam Map<String,Object> param ,
                                                                @RequestParam(required = true, defaultValue = "1") Integer index)throws Exception {
        int size = 2;
        PageUtil<Exchangescore> exchangescorePage  = exchangescoreService.queryExchangescorePageByMap(param, index, size);
        return exchangescorePage;
    }

    @RequestMapping("/saveOrUpdateExchangescore")
    @ResponseBody
    public Integer saveOrUpdateExchangescore(Exchangescore exchangescore){
        Integer flag=0;
        try {
            if(exchangescore.getId()==null || exchangescore.getId()==0){
                flag=exchangescoreService.qdtxAddExchangescore(exchangescore);
            }else{
                flag=exchangescoreService.qdtxModifyExchangescore(exchangescore);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    @RequestMapping("/getExchangescoreById")
    @ResponseBody
    public Exchangescore getExchangescoreById(Long id){

        Exchangescore exchangescore=null;
        try {
            exchangescore=exchangescoreService.getExchangescoreById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return exchangescore;
    }

    @RequestMapping("/batchRemoveExchangescore")
    @ResponseBody
    public Integer batchRemoveExchangescore(String ids){
        Integer flag=0;
        try {
            flag=exchangescoreService.qdtxBatchDeleteExchangescore(ids);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    @RequestMapping("/removeExchangescoreById")
    @ResponseBody
    public Integer removeExchangescoreById(Long id){
        Integer flag=0;
        try {
            flag=exchangescoreService.qdtxDeleteExchangescoreById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }
}
